<template>
  <el-dialog :title="'积分调整'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="auto">
      <el-form-item label="姓名" prop="name">
        <span>{{dataForm.name}}</span>
      </el-form-item>
      <el-form-item label="卡号" prop="cardNo">
        <span>{{dataForm.cardNo}}</span>
      </el-form-item>
      <el-form-item label="积分" prop="score">
        <span>{{dataForm.score}}</span>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-radio-group v-model="dataForm.type">
          <el-radio :label="3">充值</el-radio>
          <el-radio :label="4">扣除</el-radio>
          <el-radio :label="5">清空</el-radio>
        </el-radio-group>

      </el-form-item>
      <el-form-item v-if="dataForm.type != 5" :label="dataForm.type == 3 ? '充值积分' : '扣除积分'" prop="czMoney">
        <el-input-number v-model="dataForm.scoreChange" :step="1" :min="1" step-strictly></el-input-number>
      </el-form-item>
      <el-form-item label="备注信息" prop="note">
        <el-input type="textarea" :rows="2" v-model="dataForm.note" placeholder="备注信息"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        readonly: false,
        platformMember: {},
        visible: false,
        levelList: [],
        sellerId: 0,
        //
        platfromMembers: [],
        value: "",
        list: [],
        loading: false,
        states: [],
        payPwd: null,
        //
        dataForm: {
          userId: "",
          memberId: "",
          name: "",
          cardNo: "",
          sellerId: "",
          score: "",
          type: 3,
          scoreChange: 1,
          note: ""
        },
        dataRule: {

        }
      };
    },
    methods: {
      init(platformMember) {
        this.visible = true;
        this.$nextTick(() => {
          this.$http({
            url: this.$http.adornUrl(
              `/hotel/hotelmemberleveldetail/info/${platformMember}`
            ),
            method: "get",
            params: this.$http.adornParams()
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              console.log(data.hotelMemberLevelDetail)
              this.dataForm.memberId = data.hotelMemberLevelDetail.memberId;
              this.dataForm.userId = data.hotelMemberLevelDetail.memberId;
              this.dataForm.name = data.hotelMemberLevelDetail.name;
              this.dataForm.cardNo = data.hotelMemberLevelDetail.cardNo;
              this.dataForm.sellerId = data.hotelMemberLevelDetail.sellerId;
              this.dataForm.score = data.hotelMemberLevelDetail.score;
            }
          });
        });
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(
                `/hotel/hotelmemberleveldetail/integralChange`
              ),
              method: "get",
              params: this.$http.adornParams({
                memberId: this.dataForm.memberId,
                userId: this.dataForm.userId,
                name: this.dataForm.name,
                cardNo: this.dataForm.cardNo,
                sellerId: this.dataForm.sellerId,
                score: this.dataForm.score,
                type: this.dataForm.type,
                scoreChange: this.dataForm.scoreChange,
                note: this.dataForm.note
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  }
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          }
        });
      }
    }
  };
</script>
